package com.linxz.video.presenter.lifebroadcast;
import com.linxz.framework.base.ActivityLifeCycleEvent;
import com.linxz.framework.base.presenter.BasePresenter;
import com.linxz.framework.protocol.callback.ModelCallBack;
import com.linxz.video.appui.lifebroadcast.LifeBroadCastListView;
import com.linxz.video.module.lifebroadcast.LifeBroadCastModule;
import com.linxz.video.pojo.LiveBroadCastWrapBean;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.subjects.PublishSubject;

/**
 * @author Linxz
 * 创建日期：2020年06月24日 08:00
 * version：v4.5.4
 * 描述：
 */
public class LifeBroadCastListPresenter extends BasePresenter<LifeBroadCastListView, LifeBroadCastModule> {


    private List<LiveBroadCastWrapBean> liveBroadCastWrapBeanList=new ArrayList<>();
    private int page;
    private boolean refresh;

    public LifeBroadCastListPresenter(LifeBroadCastListView mView, PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        super(mView, lifecycleSubject);
    }

    @Override
    public LifeBroadCastModule createModel(PublishSubject<ActivityLifeCycleEvent> lifecycleSubject) {
        return new LifeBroadCastModule(lifecycleSubject);
    }

    public List<LiveBroadCastWrapBean> getLiveBroadCastData(){
        return this.liveBroadCastWrapBeanList;
    }


    public void refresh(){
        page=0;
        refresh=true;
        getLiveBroadCastList();
    }

    public void loadMore(){
        refresh=false;
        getLiveBroadCastList();
    }

    private void getLiveBroadCastList(){
        mModel.getLiveBroadCast(page, new ModelCallBack<List<LiveBroadCastWrapBean>>() {
            @Override
            public void onSuccess(List<LiveBroadCastWrapBean> model) {
                if (refresh){
                    liveBroadCastWrapBeanList.clear();
                    liveBroadCastWrapBeanList.addAll(model);
                }
                mView.loadDataSuccess();
                page++;
            }

            @Override
            public void onErrors(String code, String msg) {
                mView.loadError();
            }
        });
    }

}
